<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>demo</title>
  <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <p>{{count}}</p>
    <!-- @ 是 v-on 的简写 -->
    <button @click="count++">+</button>
    <!-- 有没有括号都是一样的,完全取决你需不需要传参 -->
    <button @click="add(2)">+2</button>
    <button @click="sub(2)">-2</button>
  </div>
</body>
<script type="text/javascript">
  Vue.config.productionTip = false
  // "" 里就是js环境
  new Vue({
    el: "#app",
    // 数据
    data() {
      return {
        count: 0
      }
    },
    methods: {
      add(n) {
        this.count += n
      },
      sub(n) {
        this.count -= n
      }
    }
  })
</script>

</html>